package com.jumi.microservice.service.admin;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.bean.OrderProducerBean;
import com.aliyun.openservices.ons.api.bean.ProducerBean;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jumi.microservice.common.base.dto.ExportExcelCommonResponse;
import com.jumi.microservice.common.constant.DelFlag;
import com.jumi.microservice.common.exception.BaseException;
import com.jumi.microservice.common.page.TableDataInfo;
import com.jumi.microservice.common.utils.DateUtil;
import com.jumi.microservice.common.utils.EnumUtil;
import com.jumi.microservice.config.ExpireTimeConfig;
import com.jumi.microservice.constant.PayChannelEnum;
import com.jumi.microservice.constant.compensation.*;
import com.jumi.microservice.constant.refundgoods.CancelUserFlagEnum;
import com.jumi.microservice.constant.refundgoods.RefundGoodsStatusEnum;
import com.jumi.microservice.constant.refundgoods.RefundTypeEnum;
import com.jumi.microservice.constant.refundgoods.RenounceFlagEnum;
import com.jumi.microservice.constant.reissue.*;
import com.jumi.microservice.domain.MessageTemplate;
import com.jumi.microservice.dto.PaymentResponse;
import com.jumi.microservice.dto.order.OrderLogRequest;
import com.jumi.microservice.dto.RefundRequest;
import com.jumi.microservice.dto.compensation.*;
import com.jumi.microservice.dto.compensation.transfer.PayTransferQueryRequest;
import com.jumi.microservice.dto.compensation.transfer.PayTransferRequest;
import com.jumi.microservice.dto.refundgoods.RefundGoodsGiveUpRequest;
import com.jumi.microservice.dto.refundgoods.RefundGoodsRequest;
import com.jumi.microservice.dto.reponse.UserExternalResponse;
import com.jumi.microservice.dto.serviceDto.*;
import com.jumi.microservice.dto.wallet.api.WalletInOrOutRequest;
import com.jumi.microservice.entity.Compensation;
import com.jumi.microservice.entity.RefundGoods;
import com.jumi.microservice.entity.Reissue;
import com.jumi.microservice.enumerate.OrderStatusEnum;
import com.jumi.microservice.enumerate.WalletTypeEnum;
import com.jumi.microservice.exception.CompensationExceptionEnum;
import com.jumi.microservice.exception.RefundGoodsExceptionEnum;
import com.jumi.microservice.mapper.CompensationMapper;
import com.jumi.microservice.mapper.RefundGoodsMapper;
import com.jumi.microservice.mapper.ReissueMapper;
import com.jumi.microservice.rocketmq.RocketMqConfig;
import com.jumi.microservice.rocketmq.SendMessageHandler;
import com.jumi.microservice.rocketmq.domain.CompensationEvent;
import com.jumi.microservice.rocketmq.domain.OrderAfterSaleEvent;
import com.jumi.microservice.rocketmq.domain.RefundPartEvent;
import com.jumi.microservice.service.*;
import com.jumi.microservice.transfer.AliPayTransfer;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @author Scw
 * @Date 2020-08-21 14:55
 */
@Service
public class AdminCompensationService {
    @Resource
    OrderProducerBean producerBean;
    @Resource
    ProducerBean producer;
    @Autowired
    RocketMqConfig rocketMqConfig;
    @Resource
    private CompensationMapper compensationMapper;
    @DubboReference
    private IWalletInOrOutService walletInOrOutService;
    @Resource
    private AliPayTransfer aliPayTransfer;
    @Resource
    private RefundGoodsMapper refundGoodsMapper;
    @Resource
    private ReissueMapper reissueMapper;
    @DubboReference
    private IOrderDubboService iOrderDubboService;
    @DubboReference
    private IOrderService iOrderService;
    @DubboReference
    private IPayService iPayService;
    @DubboReference
    private IUserExternalService iUserExternalService;
    @DubboReference
    private IOrderGoodsService iOrderGoodsService;
    @Resource
    SendMessageHandler sendMessageHandler;
    private static final Logger log = LoggerFactory.getLogger(AdminCompensationService.class);
    @Resource
    private ExpireTimeConfig expireTimeConfig;

    /**
     * 企业支付宝打款查询
     *
     * @param aliPayTransferQueryRequest
     * @return
     */
    public String aliPayTransferQuery(AliPayTransferQueryRequest aliPayTransferQueryRequest) {
        /*
         * 根据当前ID去查询提交参信息
         */
        int compensationId = aliPayTransferQueryRequest.getId();
        //查询当前信息
        if (compensationId <= 0) {
            throw new BaseException(CompensationExceptionEnum.ID_LESS_ZERO.getCode(), CompensationExceptionEnum.ID_LESS_ZERO.getMessage());
        }
        /*
         * 支付状态
         * 支付成功 1
         * 支付失败 2
         */
        List<Integer> statusVals = new ArrayList<Integer>();
        statusVals.add(AliPayStatusEnum.PAY_SUCCESS.getCode());
        statusVals.add(AliPayStatusEnum.PAY_FALSE.getCode());
        //查询信息
        QueryWrapper<Compensation> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", compensationId);
        queryWrapper.in("check_status", statusVals);
        queryWrapper.eq("after_sale_type", AfterSaleEnum.AFTER_SALE_BCYF.getCode());
        Compensation compensation = compensationMapper.selectOne(queryWrapper);
        if (compensation == null) {
            throw new BaseException(CompensationExceptionEnum.INFO_NO_EXIST.getCode(), CompensationExceptionEnum.INFO_NO_EXIST.getMessage());
        }
        String parameters = compensation.getParameters();
        JSONObject jsonObject = JSON.parseObject(parameters);
        //商户转账唯一订单号
        String outBizNo = jsonObject.getString("out_biz_no");
        PayTransferQueryRequest payTransferQueryRequest = new PayTransferQueryRequest();
        payTransferQueryRequest.setOutBizNo(outBizNo);
        return aliPayTransfer.transferQuery(payTransferQueryRequest);
    }

    /**
     * 补偿添加
     *
     * @param compensationAddRequest
     * @return
     */
    @org.springframework.transaction.annotation.Transactional
    public Boolean addCompensation(CompensationAddRequest compensationAddRequest) {
        Long operatorId = compensationAddRequest.getOperatorId();
        String operatorName = compensationAddRequest.getOperatorName();
        boolean resUp = false;
        Compensation compensation = new Compensation();
        //补偿邮费类型:0-默认 1-退货退款 2-换货
        byte postageType = 0;
        /*
         * compareTo 结果是: -1：小于、0 ：等于、1 ：大于
         * 判断补偿金额是否 小于等于 0
         */
        if (0 >= compensationAddRequest.getCompensationPrice().compareTo(BigDecimal.valueOf(0))) {
            throw new BaseException(CompensationExceptionEnum.MONEY_LESS_ZERO.getCode(), CompensationExceptionEnum.MONEY_LESS_ZERO.getMessage());
        }
        /*
         * 根据订单ID查询订单状态【订单表】
         * 订单状态：0-已取消、1-待付款、2-待发货、3-待收货、4-已完成
         * 发起退货：3-待收货、4-已完成
         * 补发：3-待收货、4-已完成
         * 补偿：3-待收货、4-已完成
         * 补邮：3-待收货、4-已完成
         * 换货：3-待收货、4-已完成
         * 补发漏发：3-待收货、4-已完成
         */
        //根据订单ID查询订单状态【订单表】
        Integer orderStatus = iOrderService.getOrderStatus(compensationAddRequest.getOriginalOrderId());
        if (orderStatus != null) {
            //Integer[] notAllowArr = {0, 1, 2};
            Integer[] notAllowArr = {
                    OrderStatusEnum.CANCEL.getCode().intValue(),
                    OrderStatusEnum.READY_TO_PAY.getCode().intValue(),
                    OrderStatusEnum.READY_TO_SHIP.getCode().intValue()
            };
            if (Arrays.asList(notAllowArr).contains(orderStatus)) {
                throw new BaseException(CompensationExceptionEnum.ORDER_STATUS_NOT_ALLOW.getCode(), CompensationExceptionEnum.ORDER_STATUS_NOT_ALLOW.getMessage());
            }
            //订单状态：3-待收货、4-已完成
            if (orderStatus == OrderStatusEnum.READY_TO_RECEIVE.getCode().intValue() || orderStatus == OrderStatusEnum.COMPLETED.getCode().intValue()) {
                //收货时间
                Date confirmTime = iOrderService.getConfirmTime(compensationAddRequest.getOriginalOrderId());
                if (confirmTime != null) {
                    //收货时间 + 8 < 当前时间
                    if (DateUtil.getDateAfterDay(confirmTime, Integer.parseInt(expireTimeConfig.getDiffDayOne())).before(new Date())) {
                        throw new BaseException(RefundGoodsExceptionEnum.ORDER_OVER_TIME.getCode(), RefundGoodsExceptionEnum.ORDER_OVER_TIME.getMessage());
                    }
                }
            }
        }
        /*
         * 订单商品表更新售后状态
         * 售后状态:
         *      0-正常 1-已退款
         *      2-退货审核中 3-已退货退款 4-退货退款拒绝
         *      5-补发审核中 6-已补发 7-补发拒绝
         *      8-补偿审核中 9-已补偿 10-补偿拒绝
         *      11-补邮审核中 12-已补邮费 13-补邮拒绝
         *      14-换货申请中 15-换货同意  16-换货拒绝
         *      17-补发漏发审核中 18-已补发漏发 19-补发漏发拒绝
         * 发起退货：0-正常、4-退货退款拒绝、7-补发拒绝、10-补偿拒绝、16-换货拒绝、19-补发漏发拒绝
         * 补发：0-正常、4-退货退款拒绝、7-补发拒绝、10-补偿拒绝、16-换货拒绝、19-补发漏发拒绝
         * 补偿：0-正常、4-退货退款拒绝、7-补发拒绝、10-补偿拒绝、16-换货拒绝、19-补发漏发拒绝
         * 补邮：2-退货审核中、3-已退货退款、13-补邮拒绝、14-换货申请中、15-换货同意
         * 换货：0-正常、4-退货退款拒绝、7-补发拒绝、10-补偿拒绝、16-换货拒绝、19-补发漏发拒绝
         * 补发漏发：0-正常、4-退货退款拒绝、7-补发拒绝、10-补偿拒绝、16-换货拒绝、19-补发漏发拒绝
         */
        //Integer[] notAfterSaleArr1 = {1, 2, 3, 5, 6, 8, 9, 11, 12, 13, 14, 15, 17, 18};
        Integer[] notAfterSaleArr1 = {
                AfterSaleStatusEnum.REFUND.getCode(),
                AfterSaleStatusEnum.REFUND_GOODS_APPLY.getCode(),
                AfterSaleStatusEnum.REFUND_GOODS_AGREE.getCode(),
                AfterSaleStatusEnum.REISSUE_APPLY.getCode(),
                AfterSaleStatusEnum.REISSUE_AGREE.getCode(),
                AfterSaleStatusEnum.COMPENSATION_APPLY.getCode(),
                AfterSaleStatusEnum.COMPENSATION_AGREE.getCode(),
                AfterSaleStatusEnum.COMPENSATION_POSTAGE_APPLY.getCode(),
                AfterSaleStatusEnum.COMPENSATION_POSTAGE_AGREE.getCode(),
                AfterSaleStatusEnum.COMPENSATION_POSTAGE_REFUSE.getCode(),
                AfterSaleStatusEnum.REPLACE_APPLY.getCode(),
                AfterSaleStatusEnum.REPLACE_AGREE.getCode(),
                AfterSaleStatusEnum.REISSUE_MISSED_APPLY.getCode(),
                AfterSaleStatusEnum.REISSUE_MISSED_AGREE.getCode()
        };
        //Integer[] notAfterSaleArr2 = {1, 4, 5, 6, 7, 8, 9, 10, 11, 12, 16, 17, 18，19};
        Integer[] notAfterSaleArr2 = {
                AfterSaleStatusEnum.REFUND.getCode(),
                AfterSaleStatusEnum.REFUND_GOODS_REFUSE.getCode(),
                AfterSaleStatusEnum.REISSUE_APPLY.getCode(),
                AfterSaleStatusEnum.REISSUE_AGREE.getCode(),
                AfterSaleStatusEnum.REISSUE_REFUSE.getCode(),
                AfterSaleStatusEnum.COMPENSATION_APPLY.getCode(),
                AfterSaleStatusEnum.COMPENSATION_AGREE.getCode(),
                AfterSaleStatusEnum.COMPENSATION_REFUSE.getCode(),
                AfterSaleStatusEnum.COMPENSATION_POSTAGE_APPLY.getCode(),
                AfterSaleStatusEnum.COMPENSATION_POSTAGE_AGREE.getCode(),
                AfterSaleStatusEnum.REPLACE_REFUSE.getCode(),
                AfterSaleStatusEnum.REISSUE_MISSED_APPLY.getCode(),
                AfterSaleStatusEnum.REISSUE_MISSED_AGREE.getCode(),
                AfterSaleStatusEnum.REISSUE_MISSED_REFUSE.getCode()
        };
        //根据订单ID、商品ID获取售后状态
        OrderStatusAfterSealResponse orderStatusAfterSealResponse = iOrderService.getStatusAfterSeal(compensationAddRequest.getOriginalOrderId(), compensationAddRequest.getCompensationGoodsId());
        if (orderStatusAfterSealResponse != null) {
            Integer afterSaleStatus = orderStatusAfterSealResponse.getAfterSealStatus().intValue();
            if (compensationAddRequest.getAfterSaleType().equals(AfterSaleEnum.AFTER_SALE_BCK.getCode().byteValue())) {
                if (Arrays.asList(notAfterSaleArr1).contains(afterSaleStatus)) {
                    throw new BaseException(CompensationExceptionEnum.GOODS_STATUS_NOT_ALLOW.getCode(), CompensationExceptionEnum.GOODS_STATUS_NOT_ALLOW.getMessage());
                }
                resUp = true;
            } else if (compensationAddRequest.getAfterSaleType().equals(AfterSaleEnum.AFTER_SALE_BCYF.getCode().byteValue())) {
                if (Arrays.asList(notAfterSaleArr2).contains(afterSaleStatus)) {
                    throw new BaseException(CompensationExceptionEnum.GOODS_STATUS_NOT_ALLOW.getCode(), CompensationExceptionEnum.GOODS_STATUS_NOT_ALLOW.getMessage());
                } else {
                    /*
                     * 不能发起补偿邮费
                     * 【售后状态: 3-已退货退款】
                     *  是否弃货: 2-是
                     */
                    if (afterSaleStatus == AfterSaleStatusEnum.REFUND_GOODS_AGREE.getCode().intValue()) {
                        //if (orderStatusAfterSealResponse.getRenounceFlag() == RenounceFlagEnum.RENOUNCE_YES.getCode().byteValue() && afterSaleStatus == AfterSaleStatusEnum.REFUND_GOODS_AGREE.getCode().intValue()) {
                        //throw new BaseException(CompensationExceptionEnum.GOODS_GIVEUP_CANNOT_POSTAGE.getCode(), CompensationExceptionEnum.GOODS_GIVEUP_CANNOT_POSTAGE.getMessage());
                        /*
                         * 订单Id
                         * skuId
                         * buyer_id
                         * status  退货状态: 0-待处理 1-待收货 2-待审核 3-已完成 4-已拒绝 5-已取消
                         * refund_type 售后类型: 0-退货退款 1-退款
                         * renounce_flag 是否弃货: 1-否 2-是
                         */
                        QueryWrapper<RefundGoods> queryWrapperR = new QueryWrapper<>();
                        queryWrapperR.eq("original_order_id", compensationAddRequest.getOriginalOrderId());
                        queryWrapperR.eq("refund_goods_id", compensationAddRequest.getCompensationGoodsId());
                        queryWrapperR.eq("buyer_id", compensationAddRequest.getBuyerId());
                        queryWrapperR.eq("status", RefundGoodsStatusEnum.STATUS_COMPLETE.getCode());
                        queryWrapperR.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
                        queryWrapperR.eq("renounce_flag", RenounceFlagEnum.RENOUNCE_YES.getCode());
                        queryWrapperR.orderByDesc("id");
                        queryWrapperR.last("limit 1");
                        RefundGoods refundGoods = refundGoodsMapper.selectOne(queryWrapperR);
                        if (refundGoods != null) {
                            throw new BaseException(CompensationExceptionEnum.GOODS_GIVEUP_CANNOT_POSTAGE.getCode(), CompensationExceptionEnum.GOODS_GIVEUP_CANNOT_POSTAGE.getMessage());
                        }
                        compensation.setLockFlag(LockFlagEnum.LOCK_FLAG_NO.getCode().byteValue());
                        postageType = PostageTypeEnum.POSTAGE_TYPE_REFUNDGOODS.getCode().byteValue();
                        resUp = true;
                    } else if (afterSaleStatus == AfterSaleStatusEnum.REFUND_GOODS_APPLY.getCode().intValue()) {
                        /*
                         * 订单Id
                         * skuId
                         * buyer_id
                         * status  退货状态: 0-待处理 1-待收货 2-待审核 3-已完成 4-已拒绝 5-已取消
                         * refund_type 售后类型: 0-退货退款 1-退款
                         * renounce_flag 是否弃货: 1-否 2-是
                         */
                        QueryWrapper<RefundGoods> queryWrapperR = new QueryWrapper<>();
                        queryWrapperR.eq("original_order_id", compensationAddRequest.getOriginalOrderId());
                        queryWrapperR.eq("refund_goods_id", compensationAddRequest.getCompensationGoodsId());
                        queryWrapperR.eq("buyer_id", compensationAddRequest.getBuyerId());
                        queryWrapperR.eq("status", RefundGoodsStatusEnum.STATUS_CHECK.getCode());
                        queryWrapperR.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
                        queryWrapperR.eq("renounce_flag", RenounceFlagEnum.RENOUNCE_YES.getCode());
                        queryWrapperR.orderByDesc("id");
                        queryWrapperR.last("limit 1");
                        RefundGoods refundGoods = refundGoodsMapper.selectOne(queryWrapperR);
                        if (refundGoods != null) {
                            throw new BaseException(CompensationExceptionEnum.GOODS_GIVEUP_CANNOT_POSTAGE.getCode(), CompensationExceptionEnum.GOODS_GIVEUP_CANNOT_POSTAGE.getMessage());
                        }
                        compensation.setLockFlag(LockFlagEnum.LOCK_FLAG_YES.getCode().byteValue());
                        postageType = PostageTypeEnum.POSTAGE_TYPE_REFUNDGOODS.getCode().byteValue();
                    } else if (afterSaleStatus == AfterSaleStatusEnum.REPLACE_APPLY.getCode().intValue()) {
                        compensation.setLockFlag(LockFlagEnum.LOCK_FLAG_YES.getCode().byteValue());
                        postageType = PostageTypeEnum.POSTAGE_TYPE_REISSUE.getCode().byteValue();
                    } else if (afterSaleStatus == AfterSaleStatusEnum.REPLACE_AGREE.getCode().intValue()) {
                        compensation.setLockFlag(LockFlagEnum.LOCK_FLAG_NO.getCode().byteValue());
                        postageType = PostageTypeEnum.POSTAGE_TYPE_REISSUE.getCode().byteValue();
                        resUp = true;
                    } else if (afterSaleStatus == AfterSaleStatusEnum.COMPENSATION_POSTAGE_REFUSE.getCode().intValue()) {
                        compensation.setLockFlag(LockFlagEnum.LOCK_FLAG_NO.getCode().byteValue());
                        resUp = true;
                        //查询信息
                        QueryWrapper<Compensation> queryWrapper = new QueryWrapper<>();
                        queryWrapper.eq("original_order_id", compensationAddRequest.getOriginalOrderId());
                        queryWrapper.eq("compensation_goods_id", compensationAddRequest.getCompensationGoodsId());
                        queryWrapper.eq("check_status", CheckStatusEnum.CHECK_STATUS_REFUSE.getCode());
                        queryWrapper.orderByDesc("id");
                        queryWrapper.last("limit 1");
                        Compensation compensationQ = compensationMapper.selectOne(queryWrapper);
                        if (compensationQ != null) {
                            postageType = compensationQ.getPostageType();
                        }
                    }
                }
            }
        }
        boolean res = false;
        BeanUtils.copyProperties(compensationAddRequest, compensation);
        compensation.setPostageType(postageType);
        compensation.setCompensationOrderNo(this.generateOrderSn());
        /*
         * 售后类型：0-弃货退款 1-补偿款 2-补偿邮费
         * 2-补偿邮费--默认锁定执行解锁操作
         * 是否锁定: 0-否 1-是
         */
        if (compensationAddRequest.getAfterSaleType().equals(AfterSaleEnum.AFTER_SALE_BCYF.getCode().byteValue())) {
            /*
             * 售后类型：0-弃货退款 1-补偿款 2-补偿邮费
             * 2-补偿邮费--默认锁定执行解锁操作
             * 是否锁定: 0-否 1-是
             */
            QueryWrapper<RefundGoods> queryWrapperR = new QueryWrapper<>();
            List<Integer> statusVals = new ArrayList<Integer>();
            statusVals.add(RefundGoodsStatusEnum.STATUS_DEAL_WITH.getCode());
            statusVals.add(RefundGoodsStatusEnum.STATUS_RECEIVED.getCode());
            statusVals.add(RefundGoodsStatusEnum.STATUS_COMPLETE.getCode());
            queryWrapperR.eq("original_order_id", compensationAddRequest.getOriginalOrderId());
            queryWrapperR.eq("refund_goods_id", compensationAddRequest.getCompensationGoodsId());
            queryWrapperR.eq("buyer_id", compensationAddRequest.getBuyerId());
            queryWrapperR.in("status", statusVals);
            queryWrapperR.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
            queryWrapperR.orderByDesc("id");
            queryWrapperR.last("limit 1");
            RefundGoods refundGoods = refundGoodsMapper.selectOne(queryWrapperR);
            if (refundGoods != null) {
                //退货退款
                compensation.setRefundId(refundGoods.getId());
            } else {
                //换货
                QueryWrapper<Reissue> queryWrapperReissue = new QueryWrapper<>();
                List<Integer> statusV = new ArrayList<Integer>();
                statusV.add(ReissueStatusEnum.STATUS_WAIT.getCode());
                statusV.add(ReissueStatusEnum.STATUS_PASSED.getCode());
                queryWrapperReissue.eq("original_order_id", compensationAddRequest.getOriginalOrderId());
                queryWrapperReissue.eq("goods_id", compensationAddRequest.getCompensationGoodsId());
                queryWrapperReissue.in("status", statusV);
                queryWrapperReissue.eq("reissue_type", ReissueTypeEnum.REISSUE_REPLACE.getCode());
                queryWrapperReissue.orderByDesc("id");
                queryWrapperReissue.last("limit 1");
                Reissue reissue = reissueMapper.selectOne(queryWrapperReissue);
                if (reissue != null) {
                    compensation.setRefundId(reissue.getId());
                }
            }
        }
        compensation.setCompensationPromoterId(operatorId);
        compensation.setCompensationPromoterName(operatorName);
        //根据订单ID和商品ID查询原支付订单信息
        OrderGoodsServiceDetailsRequest orderGoodsServiceDetailsRequest = new OrderGoodsServiceDetailsRequest();
        orderGoodsServiceDetailsRequest.setOrderId(compensationAddRequest.getOriginalOrderId());
        orderGoodsServiceDetailsRequest.setGoodsId(compensationAddRequest.getCompensationGoodsId());
        OrderGoodsServiceDetailsResponse orderGoodsServiceDetailsResponse = iOrderService.findOrderGoodsDetails(orderGoodsServiceDetailsRequest);
        if (orderGoodsServiceDetailsResponse == null) {
            throw new BaseException(500, "订单信息有误！");
        }
        compensation.setSelfFlag(orderGoodsServiceDetailsResponse.getSelfFlag());
        compensation.setOrderCreateTime(orderGoodsServiceDetailsResponse.getCreateTime());
        if (orderGoodsServiceDetailsResponse.getSelfFlag().equals(com.jumi.microservice.enumerate.SelfFlagEnum.YES_SELF.getCode())) {
            compensation.setSupplierId(orderGoodsServiceDetailsResponse.getRealWarehouse());
        } else {
            compensation.setSupplierId(orderGoodsServiceDetailsResponse.getSupplierId());
        }
        compensation.setGoodsName(orderGoodsServiceDetailsResponse.getGoodsName());
        compensation.setGoodsPic(orderGoodsServiceDetailsResponse.getGoodsCoverImg());
        compensation.setOrderPayNo(orderGoodsServiceDetailsResponse.getPayNo());
        compensation.setOrderThirdPartyPaySn(orderGoodsServiceDetailsResponse.getThirdPartyPaySn());
        compensation.setOrderPayType(orderGoodsServiceDetailsResponse.getPayType());
        compensation.setReceiverPhone(orderGoodsServiceDetailsResponse.getReceiverPhone());
        //根据用户ID查询手机号【用户服务提供接口】
        UserExternalResponse userExternalResponse = iUserExternalService.getUserByUid(orderGoodsServiceDetailsResponse.getBuyerId().intValue());
        String buyerPhone;
        if (userExternalResponse != null) {
            buyerPhone = userExternalResponse.getMobile();
            compensation.setBuyerPhone(buyerPhone);
        }
        if (compensationMapper.insert(compensation) > 0) {
            //Integer[] afterSaleTypeArr = {1, 2};
            Integer[] afterSaleTypeArr = {
                    AfterSaleEnum.AFTER_SALE_BCK.getCode(),
                    AfterSaleEnum.AFTER_SALE_BCYF.getCode()
            };
            if (Arrays.asList(afterSaleTypeArr).contains(compensationAddRequest.getAfterSaleType().intValue())) {
                //if (compensationAddRequest.getAfterSaleType() > 0) {
                /*
                 * 订单商品表更新售后状态
                 * 售后状态:
                 *      0-正常 1-已退款
                 *      2-退货审核中 3-已退货退款 4-退货退款拒绝
                 *      5-补发审核中 6-已补发 7-补发拒绝
                 *      8-补偿审核中 9-已补偿 10-补偿拒绝
                 *      11-补邮审核中 12-已补邮费 13-补邮拒绝
                 *      14-换货申请中 15-换货同意  16-换货拒绝
                 *      17-补发漏发审核中 18-已补发漏发 19-补发漏发拒绝
                 * 售后类型：0-弃货退款 1-补偿款 2-补偿邮费
                 * after_seal_status = 8 、after_seal_status = 11
                 */
                //int afterSealStatus = compensationAddRequest.getAfterSaleType() == 1 ? 8 : 11;
                if (resUp) {
                    int afterSealStatus = compensationAddRequest.getAfterSaleType() == AfterSaleEnum.AFTER_SALE_BCK.getCode().byteValue() ? AfterSaleStatusEnum.COMPENSATION_APPLY.getCode() : AfterSaleStatusEnum.COMPENSATION_POSTAGE_APPLY.getCode();
                    UpdateAfterSealStatusRequest updateAfterSealStatusRequest = new UpdateAfterSealStatusRequest();
                    updateAfterSealStatusRequest.setOrderId(compensationAddRequest.getOriginalOrderId());
                    updateAfterSealStatusRequest.setGoodsId(compensationAddRequest.getCompensationGoodsId());
                    updateAfterSealStatusRequest.setAfterSealStatus((byte) afterSealStatus);
                    iOrderService.updateAfterSealStatus(updateAfterSealStatusRequest);
                }
                /*
                 * 操作日志表插入相关信息
                 */
                String logInfo;
                if (compensationAddRequest.getAfterSaleType() == AfterSaleEnum.AFTER_SALE_BCK.getCode().byteValue()) {
                    logInfo = "发起补偿款：" + compensation.getGoodsName();
                } else {
                    logInfo = "发起补邮费：" + compensation.getGoodsName();
                }
                //用户标识，1 前端用户， 2 后端管理员
                Byte userFlag = CancelUserFlagEnum.USER_FLAG_ADMIN.getCode().byteValue();
                OrderLogRequest orderLogRequest = new OrderLogRequest();
                orderLogRequest.setLog(logInfo);
                orderLogRequest.setOperatorId(operatorId);
                orderLogRequest.setOperatorName(operatorName);
                orderLogRequest.setUserFlag(userFlag);
                orderLogRequest.setOrderSn(compensationAddRequest.getOriginalOrderNo());
                Boolean isAddLog = iOrderDubboService.addOrderLog(orderLogRequest);
                if (isAddLog) {
                    res = true;
                }
            } else {
                res = true;
            }
        }
        return res;
    }

    /**
     * 补偿审核批量同意
     *
     * @param compensationBatchRequest
     * @return
     */
    public Boolean batchAgreeCompensation(CompensationBatchRequest compensationBatchRequest) {
        Long operatorId = compensationBatchRequest.getOperatorId();
        String operatorName = compensationBatchRequest.getOperatorName();
        //请选择信息
        if (compensationBatchRequest.getIdStr() == null || "".equals(compensationBatchRequest.getIdStr())) {
            throw new BaseException(CompensationExceptionEnum.CHECKBOX_NO);
        }
        //获取批量打款逗号分隔组成的数组
        String[] idArr = compensationBatchRequest.getIdStr().split(",");
        for (int i = 0; i < idArr.length; i++) {
            Message message = new Message("batchAgreeCompensation", "", "", JSONObject.toJSONBytes(new CompensationEvent(Integer.valueOf(idArr[i]), operatorId, operatorName)));
            producerBean.send(message, "batchAgreeCompensation");
            log.info("批量补偿审核发送消息[{}]", JSON.toJSONString(message));

        }
        return true;
    }

    /**
     * 补偿审核同意
     *
     * @param compensationRequest
     * @return
     */
    public Boolean agreeCompensation(CompensationRequest compensationRequest) {
        boolean payRes = false;
        Long operatorId = compensationRequest.getOperatorId();
        String operatorName = compensationRequest.getOperatorName();

        boolean res = false;
        int compensationId = compensationRequest.getCompensationId();
        //查询信息
        QueryWrapper<Compensation> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", compensationId);
        queryWrapper.eq("check_status", CheckStatusEnum.CHECK_STATUS_WAIT.getCode());
        Compensation compensation = compensationMapper.selectOne(queryWrapper);
        if (compensation == null) {
            throw new BaseException(CompensationExceptionEnum.INFO_NO_EXIST.getCode(), CompensationExceptionEnum.INFO_NO_EXIST.getMessage());
        }
        compensation.setCheckStatus(CheckStatusEnum.CHECK_STATUS_AGREE.getCode().byteValue());
        compensation.setCheckOperatorId(operatorId);
        compensation.setCheckOperatorName(operatorName);
        compensation.setCheckTime(new Date());
        if (compensationMapper.updateById(compensation) > 0) {
            /*
             * 售后类型: 1-补偿款 2-补偿邮费
             * 1-返回钱包
             * 2-企业支付宝打款到个人账户
             */
            //Integer[] afterSaleTypeArr = {1, 2};
            Integer[] afterSaleTypeArr = {
                    AfterSaleEnum.AFTER_SALE_BCK.getCode(),
                    AfterSaleEnum.AFTER_SALE_BCYF.getCode()
            };
            if (Arrays.asList(afterSaleTypeArr).contains(compensation.getAfterSaleType().intValue())) {
                //if (compensation.getAfterSaleType() > 0) {
                //企业支付宝打款到个人账户
                //if (compensation.getAfterSaleType() == 2) {
                if (compensation.getAfterSaleType() == AfterSaleEnum.AFTER_SALE_BCYF.getCode().byteValue()) {
                    /*
                     *  支付宝支付
                     * 企业支付宝打款给个人用户
                     * 单笔转账到支付宝账户
                     */
                    //单位：分
                    int aliAmount = compensation.getCompensationPrice().multiply(new BigDecimal("100")).intValue();
                    String aliAccount = compensation.getPayeeAccount();
                    String aliDesc = "补偿邮费到支付宝账户";
                    String aliRealName = compensation.getPayeeRealName();
                    String aliOrderSn = this.generateOrderSn();
                    //赋值
                    PayTransferRequest payTransferRequest = new PayTransferRequest();
                    payTransferRequest.setAccountId(aliAccount);
                    payTransferRequest.setAmount(aliAmount);
                    payTransferRequest.setDesc(aliDesc);
                    payTransferRequest.setRealName(aliRealName);
                    payTransferRequest.setOrderSn(aliOrderSn);
                    Map<String, String> returnMap = aliPayTransfer.doProcess(aliPayTransfer.createContext(payTransferRequest));
                    //网关返回码  10000--接口调用成功
                    String payCode = returnMap.get("code");
                    //网关返回码描述
                    String aliMsg = returnMap.get("msg");
                    //表单提交参数信息
                    String parameters = returnMap.get("parameters");

                    //成功返回信息
                    //商户转账唯一订单号
                    String outBizNo = "";
                    if (returnMap.containsKey("out_biz_no")) {
                        outBizNo = returnMap.get("out_biz_no");
                    }
                    //支付宝转账单据号
                    String orderId = "";
                    if (returnMap.containsKey("order_id")) {
                        orderId = returnMap.get("order_id");
                    }
                    //支付时间
                    String payDate = "";
                    if (returnMap.containsKey("pay_date")) {
                        payDate = returnMap.get("pay_date");
                    }
                    //失败返回信息
                    //业务返回码
                    String subCode = "";
                    if (returnMap.containsKey("sub_code")) {
                        subCode = returnMap.get("sub_code");
                    }
                    //业务返回码描述
                    String subMsg = "";
                    if (returnMap.containsKey("sub_msg")) {
                        subMsg = returnMap.get("sub_msg");
                    }
                    //初始化
                    int payStatus;
                    String payMsg;
                    if ("10000".equals(payCode)) {
                        payRes = true;
                        //支付成功
                        payStatus = AliPayStatusEnum.PAY_SUCCESS.getCode();
                        payMsg = "网关返回码描述: " + aliMsg + " , 商户转账唯一订单号：" + outBizNo + " , 支付宝转账单据号: " + orderId + " , 支付时间: " + payDate;
                    } else {
                        //支付失败
                        payStatus = AliPayStatusEnum.PAY_FALSE.getCode();
                        payMsg = "网关返回码描述: " + aliMsg + " , 业务返回码：" + subCode + " , 业务返回码描述: " + subMsg;
                        // 更新审核状态
                        compensation.setCheckStatus(CheckStatusEnum.CHECK_STATUS_REFUSE.getCode().byteValue());
                        compensation.setCheckRemark(payMsg);
                        compensation.setCheckTime(new Date());
                        /*
                         * 订单商品表更新售后状态
                         * 售后状态:
                         *      0-正常 1-已退款
                         *      2-退货审核中 3-已退货退款 4-退货退款拒绝
                         *      5-补发审核中 6-已补发 7-补发拒绝
                         *      8-补偿审核中 9-已补偿 10-补偿拒绝
                         *      11-补邮审核中 12-已补邮费 13-补邮拒绝
                         *      14-换货申请中 15-换货同意  16-换货拒绝
                         *      17-补发漏发审核中 18-已补发漏发 19-补发漏发拒绝
                         * 售后类型：0-弃货退款 1-补偿款 2-补偿邮费
                         * after_seal_status = 13
                         */
                        //补偿邮费
                        int afterSealStatus = AfterSaleStatusEnum.COMPENSATION_POSTAGE_REFUSE.getCode();
                        UpdateAfterSealStatusRequest updateAfterSealStatusRequest = new UpdateAfterSealStatusRequest();
                        updateAfterSealStatusRequest.setOrderId(compensation.getOriginalOrderId());
                        updateAfterSealStatusRequest.setGoodsId(compensation.getCompensationGoodsId());
                        updateAfterSealStatusRequest.setAfterSealStatus((byte) afterSealStatus);
                        iOrderService.updateAfterSealStatus(updateAfterSealStatusRequest);
                    }
                    // 更新支付状态
                    compensation.setPayStatus((byte) payStatus);
                    compensation.setPayTime(new Date());
                    compensation.setPayCode(payCode);
                    compensation.setPayMsg(payMsg);
                    compensation.setParameters(parameters);
                    compensationMapper.updateById(compensation);
                } else {
                    //添加收益
                    WalletInOrOutRequest walletInOrOutRequest = new WalletInOrOutRequest();
                    walletInOrOutRequest.setRemark(AfterSaleEnum.AFTER_SALE_BCK.getDesc());
                    walletInOrOutRequest.setUserId(compensation.getBuyerId());
                    walletInOrOutRequest.setType(WalletTypeEnum.AFTER_SALE_BCK_IN.getCode());
                    walletInOrOutRequest.setAmount(compensation.getCompensationPrice());
                    walletInOrOutRequest.setOrderNo(compensation.getOriginalOrderNo());
                    boolean isAdd = walletInOrOutService.walletIn(walletInOrOutRequest).getData();
                    if (isAdd) {
                        payRes = true;
                    }
                }
            } else {
                /*
                 * 售后类型: 0-弃货退款
                 * 根据订单ID查询支付方式【订单表】
                 * 3-余额支付，则进钱包
                 */
                /*
                 * 订单支付类型：0-未支付 1-支付宝支付 2-微信支付 3-余额支付 4-聚合支付 5-支付宝H5支付 6-微信H5支付 7-微信小程序支付
                 * 记录第三方退款相关信息：1、2、5、6、7
                 */
                //Integer[] payTypeArr = {1, 2, 5, 6, 7};
                Integer[] payTypeArr = {
                        PayChannelEnum.ALI_PAY.getCode().intValue(),
                        PayChannelEnum.WX_PAY.getCode().intValue(),
                        PayChannelEnum.ALI_PAY_H5.getCode().intValue(),
                        PayChannelEnum.WX_PAY_H5.getCode().intValue(),
                        PayChannelEnum.WX_PAY_LETS.getCode().intValue()
                };
                //Integer[] payTypeArr = {2, 6, 7};
                Integer[] payWxTypeArr = {
                        PayChannelEnum.WX_PAY.getCode().intValue(),
                        PayChannelEnum.WX_PAY_H5.getCode().intValue(),
                        PayChannelEnum.WX_PAY_LETS.getCode().intValue()
                };
                //调用聚合支付退款接口
                PayChannelEnum payChannelEnum = EnumUtil.getByCode(compensation.getOrderPayType(), PayChannelEnum.class);
                RefundRequest refundRequest = new RefundRequest();
                refundRequest.setUid(compensation.getBuyerId());
                refundRequest.setAmount(compensation.getCompensationPrice());
                refundRequest.setDesc(AfterSaleEnum.AFTER_SALE_QHTK.getDesc());
                refundRequest.setPayNo(compensation.getOrderPayNo());
                refundRequest.setOrderSn(compensation.getRefundOrderNo());
                refundRequest.setThirdPartyPaySn(compensation.getOrderThirdPartyPaySn());
                refundRequest.setPayChannel(payChannelEnum);
                if (Arrays.asList(payWxTypeArr).contains(compensation.getOrderPayType().intValue())) {
                    refundRequest.setPayTotalAmount(iOrderService.getPayTotalAmount(compensation.getOrderPayNo()));
                }
                PaymentResponse paymentResponse = iPayService.refund(refundRequest);
                if (Arrays.asList(payTypeArr).contains(compensation.getOrderPayType().intValue())) {
                    UpdateWrapper<RefundGoods> refundGoodsUpdateWrapper = new UpdateWrapper<>();
                    refundGoodsUpdateWrapper.eq("id", compensation.getRefundId());
                    RefundGoods refundGoodsPay = new RefundGoods();
                    refundGoodsPay.setThirdRefundInfo(paymentResponse.getResultInfo());
                    refundGoodsMapper.update(refundGoodsPay, refundGoodsUpdateWrapper);
                }
                //支付成功
                if (paymentResponse.getResult()) {
                    /*
                     * 售后类型: 0-弃货退款 1-补偿款 2-补偿邮费
                     * 弃货退款 【退货表更新审核相关信息】
                     * 退货状态: 0-待处理 1-待收货 2-待审核 3-已完成 4-已拒绝 5-已取消
                     */
                    RefundGoodsGiveUpRequest refundGoodsGiveUpRequest = new RefundGoodsGiveUpRequest();
                    refundGoodsGiveUpRequest.setCheckFlag(CheckStatusEnum.CHECK_STATUS_AGREE.getCode().byteValue());
                    refundGoodsGiveUpRequest.setCheckRemark(CheckStatusEnum.CHECK_STATUS_AGREE.getDesc());
                    refundGoodsGiveUpRequest.setStatus(RefundGoodsStatusEnum.STATUS_COMPLETE.getCode().byteValue());
                    refundGoodsGiveUpRequest.setCheckOperatorId(operatorId);
                    refundGoodsGiveUpRequest.setCheckOperatorName(operatorName);
                    RefundGoodsRequest refundGoodsRequest = new RefundGoodsRequest();
                    refundGoodsRequest.setRefundId(compensation.getRefundId());
                    this.refundGoodsGiveUp(refundGoodsGiveUpRequest, refundGoodsRequest);
                    payRes = true;
                }
            }
            if (payRes) {
                /*
                 *  售后订单信息状态
                 */
                RefundGoods refundGoods = new RefundGoods();
                refundGoods.setId(compensation.getRefundId());
                refundGoods.setCheckOperatorId(operatorId);
                refundGoods.setCheckOperatorName(operatorName);
                refundGoods.setCheckTime(new Date());
                refundGoods.setCheckFlag(CheckStatusEnum.CHECK_STATUS_AGREE.getCode().byteValue());
                refundGoods.setStatus(RefundGoodsStatusEnum.STATUS_COMPLETE.getCode().byteValue());
                refundGoodsMapper.updateById(refundGoods);
                /*
                 * 订单商品表更新售后状态
                 * 售后状态:
                 *      0-正常 1-已退款
                 *      2-退货审核中 3-已退货退款 4-退货退款拒绝
                 *      5-补发审核中 6-已补发 7-补发拒绝
                 *      8-补偿审核中 9-已补偿 10-补偿拒绝
                 *      11-补邮审核中 12-已补邮费 13-补邮拒绝
                 *      14-换货申请中 15-换货同意  16-换货拒绝
                 *      17-补发漏发审核中 18-已补发漏发 19-补发漏发拒绝
                 * 售后类型：0-弃货退款 1-补偿款 2-补偿邮费
                 * after_seal_status = 3 、after_seal_status = 9 、after_seal_status = 12
                 */
                //int afterSealStatus = compensation.getAfterSaleType() == 0 ? 3 : (compensation.getAfterSaleType() == 1 ? 9 : 12);
                int afterSealStatus = compensation.getAfterSaleType() == AfterSaleEnum.AFTER_SALE_QHTK.getCode().intValue() ? AfterSaleStatusEnum.REFUND_GOODS_AGREE.getCode() : (compensation.getAfterSaleType() == AfterSaleEnum.AFTER_SALE_BCK.getCode().intValue() ? AfterSaleStatusEnum.COMPENSATION_AGREE.getCode() : AfterSaleStatusEnum.COMPENSATION_POSTAGE_AGREE.getCode());
                UpdateAfterSealStatusRequest updateAfterSealStatusRequest = new UpdateAfterSealStatusRequest();
                updateAfterSealStatusRequest.setOrderId(compensation.getOriginalOrderId());
                updateAfterSealStatusRequest.setGoodsId(compensation.getCompensationGoodsId());
                updateAfterSealStatusRequest.setAfterSealStatus((byte) afterSealStatus);
                Boolean isStatus = iOrderService.updateAfterSealStatus(updateAfterSealStatusRequest);

                /*
                 * 弃货退款
                 * 先更新 订单商品售后状态，再去判断是否需要更新 订单状态
                 */
                if (compensation.getAfterSaleType() == AfterSaleEnum.AFTER_SALE_QHTK.getCode().intValue()) {
                    /*
                     * 根据退货ID查询退货相关信息
                     */
                    QueryWrapper<RefundGoods> queryWrapperRefundGoods = new QueryWrapper<>();
                    queryWrapperRefundGoods.eq("id", compensation.getRefundId());
                    RefundGoods refundGoodsSendMess = refundGoodsMapper.selectOne(queryWrapperRefundGoods);
                    if (refundGoodsSendMess != null) {
                        /*
                         * 给用户服务发送消息
                         */
                        OrderAfterSaleEvent orderAfterSaleEvent = new OrderAfterSaleEvent();
                        //订单ID
                        orderAfterSaleEvent.setOrderId(refundGoodsSendMess.getOriginalOrderId());
                        //订单编号
                        orderAfterSaleEvent.setOrderNo(refundGoodsSendMess.getOriginalOrderNo());
                        //skuId
                        orderAfterSaleEvent.setSkuId(refundGoodsSendMess.getRefundGoodsId());
                        //spuId
                        orderAfterSaleEvent.setSpuId(refundGoodsSendMess.getRefundSpuId());
                        //售后数量
                        orderAfterSaleEvent.setAfterNum(refundGoodsSendMess.getRefundNum());
                        //购买数量
                        orderAfterSaleEvent.setBuyNum(refundGoodsSendMess.getGoodsAmount());

                        Message message = new Message("orderAfterSale", "", "", JSONObject.toJSONBytes(orderAfterSaleEvent));
                        producer.send(message);

                        //给发票发消息
                        RefundPartEvent refundPartEvent = new RefundPartEvent();
                        //售后类型：0-退款 1-退货
                        refundPartEvent.setAfterType(1);
                        //是否全部订单：0-否 1-是
                        refundPartEvent.setComplete(0);
                        //订单编号
                        refundPartEvent.setOrderNo(refundGoodsSendMess.getOriginalOrderNo());
                        //商品skuId
                        refundPartEvent.setGoodsId(refundGoodsSendMess.getRefundGoodsId());
                        Message message2 = new Message("invoice", "", "", JSONObject.toJSONBytes(refundPartEvent));
                        producer.send(message2);

                        //推送订单退款通知消息
                        MessageTemplate messageTemplate = sendMessageHandler.getMessageTemplate(9);
                        String appMessageContent = messageTemplate == null ? "" : messageTemplate.getSmtAppContent().replace("{}", compensation.getCompensationPrice().toString());
                        String stationMessageContent = messageTemplate == null ? "" : messageTemplate.getSmtMessageContent().replace("{}", compensation.getCompensationPrice().toString());
                        sendMessageHandler.sendMessage("", appMessageContent, stationMessageContent,
                                refundGoodsSendMess.getGoodsPic(), refundGoodsSendMess.getBuyerId(), 9);
                    }
                }

                /*
                 * 操作日志表插入相关信息
                 */
                String logInfo = "售后处理-";
                if (compensation.getAfterSaleType() == AfterSaleEnum.AFTER_SALE_BCK.getCode().byteValue()) {
                    logInfo += "同意补偿款";
                } else if (compensation.getAfterSaleType() == AfterSaleEnum.AFTER_SALE_BCYF.getCode().byteValue()) {
                    logInfo += "同意补邮费";
                } else {
                    logInfo += "同意退货退款并弃货";
                }
                //用户标识，1 前端用户， 2 后端管理员
                Byte userFlag = CancelUserFlagEnum.USER_FLAG_ADMIN.getCode().byteValue();
                OrderLogRequest orderLogRequest = new OrderLogRequest();
                orderLogRequest.setLog(logInfo);
                orderLogRequest.setOperatorId(operatorId);
                orderLogRequest.setOperatorName(operatorName);
                orderLogRequest.setUserFlag(userFlag);
                orderLogRequest.setOrderSn(compensation.getOriginalOrderNo());
                Boolean isAddLog = iOrderDubboService.addOrderLog(orderLogRequest);
                if (isStatus && isAddLog) {
                    res = true;
                }
            }
        }
        return res;
    }

    /**
     * 弃货审核
     *
     * @param refundGoodsGiveUpRequest
     * @param refundGoodsRequest
     * @return
     */
    private Boolean refundGoodsGiveUp(RefundGoodsGiveUpRequest refundGoodsGiveUpRequest, RefundGoodsRequest
            refundGoodsRequest) {
        boolean res = false;
        int refundId = refundGoodsRequest.getRefundId();
        //查询信息
        QueryWrapper<RefundGoods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", refundId);
        queryWrapper.eq("status", RefundGoodsStatusEnum.STATUS_CHECK.getCode());
        queryWrapper.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
        RefundGoods refundGoods = refundGoodsMapper.selectOne(queryWrapper);
        if (refundGoods == null) {
            throw new BaseException(RefundGoodsExceptionEnum.INFO_NO_EXIST.getCode(), RefundGoodsExceptionEnum.INFO_NO_EXIST.getMessage());
        }
        refundGoods.setCheckFlag(refundGoodsGiveUpRequest.getCheckFlag());
        refundGoods.setCheckRemark(refundGoodsGiveUpRequest.getCheckRemark());
        refundGoods.setCheckOperatorId(refundGoodsGiveUpRequest.getCheckOperatorId());
        refundGoods.setCheckOperatorName(refundGoodsGiveUpRequest.getCheckOperatorName());
        refundGoods.setCheckTime(new Date());
        if (refundGoodsMapper.updateById(refundGoods) > 0) {
            if (refundGoodsGiveUpRequest.getCheckFlag() == CheckStatusEnum.CHECK_STATUS_AGREE.getCode().byteValue()) {
                /*
                 * 售后状态:
                 *      0-正常 1-已退款
                 *      2-退货审核中 3-已退货退款 4-退货退款拒绝
                 *      5-补发审核中 6-已补发 7-补发拒绝
                 *      8-补偿审核中 9-已补偿 10-补偿拒绝
                 *      11-补邮审核中 12-已补邮费 13-补邮拒绝
                 *      14-换货申请中 15-换货同意  16-换货拒绝
                 *      17-补发漏发审核中 18-已补发漏发 19-补发漏发拒绝
                 * after_seal_status = 3
                 */
                UpdateReturnInfoRequest updateReturnInfoRequest = new UpdateReturnInfoRequest();
                updateReturnInfoRequest.setOrderId(refundGoods.getOriginalOrderId());
                updateReturnInfoRequest.setGoodsId(refundGoods.getRefundGoodsId());
                updateReturnInfoRequest.setReturnCount(refundGoods.getRefundNum());
                updateReturnInfoRequest.setReturnPrice(refundGoods.getRefundPrice());
                updateReturnInfoRequest.setReturnPostage(refundGoods.getRefundPostage());
                res = iOrderService.updateReturnInfo(updateReturnInfoRequest);
            }
        }
        return res;
    }

    /**
     * 补偿审核拒绝
     *
     * @param compensationCheckRequest
     * @param compensationRequest
     * @return
     */
    @org.springframework.transaction.annotation.Transactional
    public Boolean refuseCompensation(CompensationCheckRequest compensationCheckRequest, CompensationRequest
            compensationRequest) {
        Long operatorId = compensationRequest.getOperatorId();
        String operatorName = compensationRequest.getOperatorName();

        boolean res = false;
        int compensationId = compensationRequest.getCompensationId();
        //查询信息
        QueryWrapper<Compensation> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", compensationId);
        queryWrapper.eq("check_status", CheckStatusEnum.CHECK_STATUS_WAIT.getCode());
        Compensation compensation = compensationMapper.selectOne(queryWrapper);
        if (compensation == null) {
            throw new BaseException(CompensationExceptionEnum.INFO_NO_EXIST.getCode(), CompensationExceptionEnum.INFO_NO_EXIST.getMessage());
        }
        compensation.setCheckStatus(CheckStatusEnum.CHECK_STATUS_REFUSE.getCode().byteValue());
        compensation.setCheckRemark(compensationCheckRequest.getCheckRemark());
        compensation.setCheckOperatorId(operatorId);
        compensation.setCheckOperatorName(operatorName);
        compensation.setCheckTime(new Date());
        if (compensationMapper.updateById(compensation) > 0) {
            //弃货
            if (compensation.getAfterSaleType() == AfterSaleEnum.AFTER_SALE_QHTK.getCode().byteValue()) {
                /*
                 *  售后订单信息状态
                 */
                RefundGoods refundGoods = new RefundGoods();
                refundGoods.setId(compensation.getRefundId());
                refundGoods.setCheckRemark(compensationCheckRequest.getCheckRemark());
                refundGoods.setCheckOperatorId(operatorId);
                refundGoods.setCheckOperatorName(operatorName);
                refundGoods.setCheckTime(new Date());
                refundGoods.setCheckFlag(CheckStatusEnum.CHECK_STATUS_REFUSE.getCode().byteValue());
                refundGoods.setStatus(RefundGoodsStatusEnum.STATUS_REFUSE.getCode().byteValue());
                refundGoodsMapper.updateById(refundGoods);
            }
            /*
             * 订单商品表更新售后状态
             * 售后状态:
             *      0-正常 1-已退款
             *      2-退货审核中 3-已退货退款 4-退货退款拒绝
             *      5-补发审核中 6-已补发 7-补发拒绝
             *      8-补偿审核中 9-已补偿 10-补偿拒绝
             *      11-补邮审核中 12-已补邮费 13-补邮拒绝
             *      14-换货申请中 15-换货同意  16-换货拒绝
             *      17-补发漏发审核中 18-已补发漏发 19-补发漏发拒绝
             * 售后类型：0-弃货退款 1-补偿款 2-补偿邮费
             * after_seal_status = 4 、after_seal_status = 10 、after_seal_status = 13
             */
            //int afterSealStatus = compensation.getAfterSaleType() == 0 ? 4 : (compensation.getAfterSaleType() == 1 ? 10 : 13);
            int afterSealStatus = compensation.getAfterSaleType() == AfterSaleEnum.AFTER_SALE_QHTK.getCode().intValue() ? AfterSaleStatusEnum.REFUND_GOODS_REFUSE.getCode() : (compensation.getAfterSaleType() == AfterSaleEnum.AFTER_SALE_BCK.getCode().intValue() ? AfterSaleStatusEnum.COMPENSATION_REFUSE.getCode() : AfterSaleStatusEnum.COMPENSATION_POSTAGE_REFUSE.getCode());
            UpdateAfterSealStatusRequest updateAfterSealStatusRequest = new UpdateAfterSealStatusRequest();
            updateAfterSealStatusRequest.setOrderId(compensation.getOriginalOrderId());
            updateAfterSealStatusRequest.setGoodsId(compensation.getCompensationGoodsId());
            updateAfterSealStatusRequest.setAfterSealStatus((byte) afterSealStatus);
            Boolean isStatus = iOrderService.updateAfterSealStatus(updateAfterSealStatusRequest);

            /*
             * 操作日志表插入相关信息
             */
            String logInfo = "售后处理-";
            if (compensation.getAfterSaleType() == AfterSaleEnum.AFTER_SALE_BCK.getCode().byteValue()) {
                logInfo += "拒绝补偿款";
            } else if (compensation.getAfterSaleType() == AfterSaleEnum.AFTER_SALE_BCYF.getCode().byteValue()) {
                logInfo += "拒绝补邮费";
            } else {
                logInfo += "拒绝退货退款并弃货";
            }
            //用户标识，1 前端用户， 2 后端管理员
            Byte userFlag = CancelUserFlagEnum.USER_FLAG_ADMIN.getCode().byteValue();
            OrderLogRequest orderLogRequest = new OrderLogRequest();
            orderLogRequest.setLog(logInfo);
            orderLogRequest.setOperatorId(operatorId);
            orderLogRequest.setOperatorName(operatorName);
            orderLogRequest.setUserFlag(userFlag);
            orderLogRequest.setOrderSn(compensation.getOriginalOrderNo());
            Boolean isAddLog = iOrderDubboService.addOrderLog(orderLogRequest);
            if (isStatus && isAddLog) {
                res = true;
            }
        }
        return res;
    }

    /**
     * 补偿审核信息
     *
     * @param compensationRequest
     * @return
     */
    public CompensationInfoResponse compensationInfo(CompensationRequest compensationRequest) {
        int compensationId = compensationRequest.getCompensationId();
        //查询信息
        QueryWrapper<Compensation> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", compensationId);
        Compensation compensation = compensationMapper.selectOne(queryWrapper);
        if (compensation == null) {
            throw new BaseException(CompensationExceptionEnum.INFO_NO_EXIST.getCode(), CompensationExceptionEnum.INFO_NO_EXIST.getMessage());
        }
        CompensationInfoResponse compensationInfoResponse = new CompensationInfoResponse();
        BeanUtils.copyProperties(compensation, compensationInfoResponse);
        return compensationInfoResponse;
    }

    /**
     * 全部列表
     *
     * @param request
     * @return
     */
    public TableDataInfo<CompensationListResponse> compensationList(CompensationListRequest request) {
        QueryWrapper<Compensation> queryWrapper = new QueryWrapper<>();
        /*
         * 补偿邮费
         * 默认锁定，锁定的不展示
         * 是否锁定: 0-否 1-是
         */
        queryWrapper.eq("lock_flag", LockFlagEnum.LOCK_FLAG_NO.getCode());
        queryWrapper.orderByDesc("id");
        //售后类型
        if (request.getAfterSaleType() != null) {
            queryWrapper.eq("after_sale_type", request.getAfterSaleType());
        }
        //商品名称
        if (request.getGoodsName() != null && !"".equals(request.getGoodsName())) {
            queryWrapper.like("goods_name", request.getGoodsName());
        }
        //供货商类型：1-供货商【非自营】 2-仓库【自营】
        if (request.getSupplierType() != null) {
            if (request.getSupplierId() != null) {
                queryWrapper.eq("supplier_id", request.getSupplierId());
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_ONE.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_NO.getCode());
                }
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_TWO.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_YES.getCode());
                }
            }
        }
        //手机号类型：1-购买人手机号 2-收件人手机号
        if (request.getPhoneType() != null) {
            if (request.getPhone() != null && !"".equals(request.getPhone())) {
                if (request.getPhoneType() == PhoneTypeEnum.PHONE_TYPE_BUY.getCode().byteValue()) {
                    queryWrapper.eq("buyer_phone", request.getPhone());
                }
                if (request.getPhoneType() == PhoneTypeEnum.PHONE_TYPE_RECEIVE.getCode().byteValue()) {
                    queryWrapper.eq("receiver_phone", request.getPhone());
                }
            }
        }
        //订单编号
        if (request.getOriginalOrderNo() != null && !"".equals(request.getOriginalOrderNo())) {
            queryWrapper.eq("original_order_no", request.getOriginalOrderNo());
        }
        IPage<Compensation> page = new Page<>(request.getPageNum(), request.getPageSize());
        page = compensationMapper.selectPage(page, queryWrapper);
        List<Compensation> compensations = page.getRecords();
        List<CompensationListResponse> result = new ArrayList<>();
        if (compensations.size() > 0) {
            for (Compensation compensation : compensations) {
                CompensationListResponse compensationListResponse = new CompensationListResponse();
                BeanUtils.copyProperties(compensation, compensationListResponse);
                //根据订单ID和商品ID查询商品名称--【订单商品表】
                OrderGoodsServiceDetailsRequest orderGoodsServiceDetailsRequest = new OrderGoodsServiceDetailsRequest();
                orderGoodsServiceDetailsRequest.setOrderId(compensation.getOriginalOrderId());
                orderGoodsServiceDetailsRequest.setGoodsId(compensation.getCompensationGoodsId());
                OrderGoodsServiceDetailsResponse orderGoodsServiceDetailsResponse = iOrderService.findOrderGoodsDetails(orderGoodsServiceDetailsRequest);
                if (orderGoodsServiceDetailsResponse != null) {
                    compensationListResponse.setGoodsName(orderGoodsServiceDetailsResponse.getGoodsName());
                    compensationListResponse.setGoodsPic(orderGoodsServiceDetailsResponse.getGoodsCoverImg());
                }
                if (compensation.getRefundId() > 0) {
                    QueryWrapper<RefundGoods> queryWrapperRefundGoods = new QueryWrapper<>();
                    queryWrapperRefundGoods.eq("id", compensation.getRefundId());
                    queryWrapperRefundGoods.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
                    RefundGoods refundGoods = refundGoodsMapper.selectOne(queryWrapperRefundGoods);
                    if (refundGoods != null) {
                        /*
                         * 售后类型 0-弃货退款 1-补偿款 2-补偿邮费
                         * 0-弃货退款：处理人
                         * 2-补偿邮费：收货人
                         */
                        if (compensation.getAfterSaleType().equals(AfterSaleEnum.AFTER_SALE_QHTK.getCode().byteValue())) {
                            compensationListResponse.setAfterTypeName("已弃货");
                            compensationListResponse.setOperatorName(refundGoods.getDealWithOperatorName());
                        } else {
                            compensationListResponse.setAfterTypeName("已收货");
                            compensationListResponse.setOperatorName(refundGoods.getReceivedOperatorName());
                        }
                    }
                } else {
                    compensationListResponse.setAfterTypeName("");
                    compensationListResponse.setOperatorName("");
                }
                result.add(compensationListResponse);
            }
        }
        TableDataInfo<CompensationListResponse> dataInfo = new TableDataInfo<>();
        dataInfo.setRows(result);
        dataInfo.setTotal(page.getTotal());
        return dataInfo;
    }

    /**
     * 待审核列表
     *
     * @param request
     * @return
     */
    public TableDataInfo<CompensationCheckListResponse> compensationCheckList(CompensationListRequest request) {
        QueryWrapper<Compensation> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("check_status", CheckStatusEnum.CHECK_STATUS_WAIT.getCode());
        /*
         * 补偿邮费
         * 默认锁定，锁定的不展示
         * 是否锁定: 0-否 1-是
         */
        queryWrapper.eq("lock_flag", LockFlagEnum.LOCK_FLAG_NO.getCode());
        queryWrapper.orderByDesc("id");
        //售后类型
        if (request.getAfterSaleType() != null) {
            queryWrapper.eq("after_sale_type", request.getAfterSaleType());
        }
        //商品名称
        if (request.getGoodsName() != null && !"".equals(request.getGoodsName())) {
            queryWrapper.like("goods_name", request.getGoodsName());
        }
        //供货商类型：1-供货商【非自营】 2-仓库【自营】
        if (request.getSupplierType() != null) {
            if (request.getSupplierId() != null) {
                queryWrapper.eq("supplier_id", request.getSupplierId());
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_ONE.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_NO.getCode());
                }
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_TWO.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_YES.getCode());
                }
            }
        }
        //手机号类型：1-购买人手机号 2-收件人手机号
        if (request.getPhoneType() != null) {
            if (request.getPhone() != null && !"".equals(request.getPhone())) {
                if (request.getPhoneType() == PhoneTypeEnum.PHONE_TYPE_BUY.getCode().byteValue()) {
                    queryWrapper.eq("buyer_phone", request.getPhone());
                }
                if (request.getPhoneType() == PhoneTypeEnum.PHONE_TYPE_RECEIVE.getCode().byteValue()) {
                    queryWrapper.eq("receiver_phone", request.getPhone());
                }
            }
        }
        //订单编号
        if (request.getOriginalOrderNo() != null && !"".equals(request.getOriginalOrderNo())) {
            queryWrapper.eq("original_order_no", request.getOriginalOrderNo());
        }
        IPage<Compensation> page = new Page<>(request.getPageNum(), request.getPageSize());
        page = compensationMapper.selectPage(page, queryWrapper);
        List<Compensation> compensations = page.getRecords();
        List<CompensationCheckListResponse> result = new ArrayList<>();
        if (compensations.size() > 0) {
            for (Compensation compensation : compensations) {
                CompensationCheckListResponse compensationCheckListResponse = new CompensationCheckListResponse();
                BeanUtils.copyProperties(compensation, compensationCheckListResponse);
                //根据用户ID查询用户姓名【用户服务提供接口】
                String userName = "";
                UserExternalResponse userExternalResponse = iUserExternalService.getUserByUid(compensation.getBuyerId().intValue());
                if (userExternalResponse != null) {
                    userName = userExternalResponse.getNickName();
                }
                compensationCheckListResponse.setUserName(userName);
                //根据订单ID和商品ID查询下单时间和商品名称--【订单商品表】
                OrderGoodsServiceDetailsRequest orderGoodsServiceDetailsRequest = new OrderGoodsServiceDetailsRequest();
                orderGoodsServiceDetailsRequest.setOrderId(compensation.getOriginalOrderId());
                orderGoodsServiceDetailsRequest.setGoodsId(compensation.getCompensationGoodsId());
                OrderGoodsServiceDetailsResponse orderGoodsServiceDetailsResponse = iOrderService.findOrderGoodsDetails(orderGoodsServiceDetailsRequest);
                if (orderGoodsServiceDetailsResponse != null) {
                    compensationCheckListResponse.setGoodsName(orderGoodsServiceDetailsResponse.getGoodsName());
                    compensationCheckListResponse.setGoodsPic(orderGoodsServiceDetailsResponse.getGoodsCoverImg());
                    compensationCheckListResponse.setOrderCreateTime(orderGoodsServiceDetailsResponse.getCreateTime());
                }
                if (compensation.getRefundId() > 0) {
                    QueryWrapper<RefundGoods> queryWrapperRefundGoods = new QueryWrapper<>();
                    queryWrapperRefundGoods.eq("id", compensation.getRefundId());
                    queryWrapperRefundGoods.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
                    RefundGoods refundGoods = refundGoodsMapper.selectOne(queryWrapperRefundGoods);
                    if (refundGoods != null) {
                        /*
                         * 售后类型 0-弃货退款 1-补偿款 2-补偿邮费
                         * 0-弃货退款：处理人
                         * 2-补偿邮费：收货人
                         */
                        if (compensation.getAfterSaleType().equals(AfterSaleEnum.AFTER_SALE_QHTK.getCode().byteValue())) {
                            compensationCheckListResponse.setAfterTypeName("已弃货");
                            compensationCheckListResponse.setOperatorName(refundGoods.getDealWithOperatorName());
                        } else {
                            compensationCheckListResponse.setAfterTypeName("已收货");
                            compensationCheckListResponse.setOperatorName(refundGoods.getReceivedOperatorName());
                        }
                    }
                } else {
                    compensationCheckListResponse.setAfterTypeName("");
                    compensationCheckListResponse.setOperatorName("");
                }
                result.add(compensationCheckListResponse);
            }
        }
        TableDataInfo<CompensationCheckListResponse> dataInfo = new TableDataInfo<>();
        dataInfo.setRows(result);
        dataInfo.setTotal(page.getTotal());
        return dataInfo;
    }

    /**
     * 已同意列表
     *
     * @param request
     * @return
     */
    public TableDataInfo<CompensationAgreeListResponse> compensationAgreeList(CompensationStepListRequest request) {
        QueryWrapper<Compensation> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("check_status", CheckStatusEnum.CHECK_STATUS_AGREE.getCode());
        /*
         * 补偿邮费
         * 默认锁定，锁定的不展示
         * 是否锁定: 0-否 1-是
         */
        queryWrapper.eq("lock_flag", LockFlagEnum.LOCK_FLAG_NO.getCode());
        queryWrapper.orderByDesc("id");
        //售后类型
        if (request.getAfterSaleType() != null) {
            queryWrapper.eq("after_sale_type", request.getAfterSaleType());
        }
        //商品名称
        if (request.getGoodsName() != null && !"".equals(request.getGoodsName())) {
            queryWrapper.like("goods_name", request.getGoodsName());
        }
        //供货商类型：1-供货商【非自营】 2-仓库【自营】
        if (request.getSupplierType() != null) {
            if (request.getSupplierId() != null) {
                queryWrapper.eq("supplier_id", request.getSupplierId());
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_ONE.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_NO.getCode());
                }
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_TWO.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_YES.getCode());
                }
            }
        }
        IPage<Compensation> page = new Page<>(request.getPageNum(), request.getPageSize());
        page = compensationMapper.selectPage(page, queryWrapper);
        List<Compensation> compensations = page.getRecords();
        List<CompensationAgreeListResponse> result = new ArrayList<>();
        if (compensations.size() > 0) {
            for (Compensation compensation : compensations) {
                CompensationAgreeListResponse compensationAgreeListResponse = new CompensationAgreeListResponse();
                BeanUtils.copyProperties(compensation, compensationAgreeListResponse);
                //根据订单ID和商品ID查询下单时间和商品名称--【订单商品表】
                OrderGoodsServiceDetailsRequest orderGoodsServiceDetailsRequest = new OrderGoodsServiceDetailsRequest();
                orderGoodsServiceDetailsRequest.setOrderId(compensation.getOriginalOrderId());
                orderGoodsServiceDetailsRequest.setGoodsId(compensation.getCompensationGoodsId());
                OrderGoodsServiceDetailsResponse orderGoodsServiceDetailsResponse = iOrderService.findOrderGoodsDetails(orderGoodsServiceDetailsRequest);
                if (orderGoodsServiceDetailsResponse != null) {
                    compensationAgreeListResponse.setGoodsName(orderGoodsServiceDetailsResponse.getGoodsName());
                    compensationAgreeListResponse.setGoodsPic(orderGoodsServiceDetailsResponse.getGoodsCoverImg());
                }
                if (compensation.getRefundId() > 0) {
                    QueryWrapper<RefundGoods> queryWrapperRefundGoods = new QueryWrapper<>();
                    queryWrapperRefundGoods.eq("id", compensation.getRefundId());
                    queryWrapperRefundGoods.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
                    RefundGoods refundGoods = refundGoodsMapper.selectOne(queryWrapperRefundGoods);
                    if (refundGoods != null) {
                        /*
                         * 售后类型 0-弃货退款 1-补偿款 2-补偿邮费
                         * 0-弃货退款：处理人
                         * 2-补偿邮费：收货人
                         */
                        if (compensation.getAfterSaleType().equals(AfterSaleEnum.AFTER_SALE_QHTK.getCode().byteValue())) {
                            compensationAgreeListResponse.setAfterTypeName("已弃货");
                            compensationAgreeListResponse.setOperatorName(refundGoods.getDealWithOperatorName());
                        } else {
                            compensationAgreeListResponse.setAfterTypeName("已收货");
                            compensationAgreeListResponse.setOperatorName(refundGoods.getReceivedOperatorName());
                        }
                    }
                } else {
                    compensationAgreeListResponse.setAfterTypeName("");
                    compensationAgreeListResponse.setOperatorName("");
                }
                result.add(compensationAgreeListResponse);
            }
        }
        TableDataInfo<CompensationAgreeListResponse> dataInfo = new TableDataInfo<>();
        dataInfo.setRows(result);
        dataInfo.setTotal(page.getTotal());
        return dataInfo;
    }


    /**
     * 已拒绝列表
     *
     * @param request
     * @return
     */
    public TableDataInfo<CompensationRefuseListResponse> compensationRefuseList(CompensationStepListRequest request) {
        QueryWrapper<Compensation> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("check_status", CheckStatusEnum.CHECK_STATUS_REFUSE.getCode());
        /*
         * 补偿邮费
         * 默认锁定，锁定的不展示
         * 是否锁定: 0-否 1-是
         */
        queryWrapper.eq("lock_flag", LockFlagEnum.LOCK_FLAG_NO.getCode());
        queryWrapper.orderByDesc("id");
        //售后类型
        if (request.getAfterSaleType() != null) {
            queryWrapper.eq("after_sale_type", request.getAfterSaleType());
        }
        //商品名称
        if (request.getGoodsName() != null && !"".equals(request.getGoodsName())) {
            queryWrapper.like("goods_name", request.getGoodsName());
        }
        //供货商类型：1-供货商【非自营】 2-仓库【自营】
        if (request.getSupplierType() != null) {
            if (request.getSupplierId() != null) {
                queryWrapper.eq("supplier_id", request.getSupplierId());
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_ONE.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_NO.getCode());
                }
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_TWO.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_YES.getCode());
                }
            }
        }
        IPage<Compensation> page = new Page<>(request.getPageNum(), request.getPageSize());
        page = compensationMapper.selectPage(page, queryWrapper);
        List<Compensation> compensations = page.getRecords();
        List<CompensationRefuseListResponse> result = new ArrayList<>();
        if (compensations.size() > 0) {
            for (Compensation compensation : compensations) {
                CompensationRefuseListResponse compensationRefuseListResponse = new CompensationRefuseListResponse();
                BeanUtils.copyProperties(compensation, compensationRefuseListResponse);
                //根据订单ID和商品ID查询下单时间和商品名称--【订单商品表】
                OrderGoodsServiceDetailsRequest orderGoodsServiceDetailsRequest = new OrderGoodsServiceDetailsRequest();
                orderGoodsServiceDetailsRequest.setOrderId(compensation.getOriginalOrderId());
                orderGoodsServiceDetailsRequest.setGoodsId(compensation.getCompensationGoodsId());
                OrderGoodsServiceDetailsResponse orderGoodsServiceDetailsResponse = iOrderService.findOrderGoodsDetails(orderGoodsServiceDetailsRequest);
                if (orderGoodsServiceDetailsResponse != null) {
                    compensationRefuseListResponse.setGoodsName(orderGoodsServiceDetailsResponse.getGoodsName());
                    compensationRefuseListResponse.setGoodsPic(orderGoodsServiceDetailsResponse.getGoodsCoverImg());
                }
                if (compensation.getRefundId() > 0) {
                    QueryWrapper<RefundGoods> queryWrapperRefundGoods = new QueryWrapper<>();
                    queryWrapperRefundGoods.eq("id", compensation.getRefundId());
                    queryWrapperRefundGoods.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
                    RefundGoods refundGoods = refundGoodsMapper.selectOne(queryWrapperRefundGoods);
                    if (refundGoods != null) {
                        /*
                         * 售后类型 0-弃货退款 1-补偿款 2-补偿邮费
                         * 0-弃货退款：处理人
                         * 2-补偿邮费：收货人
                         */
                        if (compensation.getAfterSaleType().equals(AfterSaleEnum.AFTER_SALE_QHTK.getCode().byteValue())) {
                            compensationRefuseListResponse.setAfterTypeName("已弃货");
                            compensationRefuseListResponse.setOperatorName(refundGoods.getDealWithOperatorName());
                        } else {
                            compensationRefuseListResponse.setAfterTypeName("已收货");
                            compensationRefuseListResponse.setOperatorName(refundGoods.getReceivedOperatorName());
                        }
                    }
                } else {
                    compensationRefuseListResponse.setAfterTypeName("");
                    compensationRefuseListResponse.setOperatorName("");
                }
                result.add(compensationRefuseListResponse);
            }
        }
        TableDataInfo<CompensationRefuseListResponse> dataInfo = new TableDataInfo<>();
        dataInfo.setRows(result);
        dataInfo.setTotal(page.getTotal());
        return dataInfo;
    }

    /**
     * 全部导出excel
     *
     * @param request
     * @return
     */
    public ExportExcelCommonResponse<ExportCompensationResponse> exportExcel(ExportCompensationRequest request) {
        request.checkRequest();
        QueryWrapper<Compensation> queryWrapper = new QueryWrapper<>();
        /*
         * 补偿邮费
         * 默认锁定，锁定的不展示
         * 是否锁定: 0-否 1-是
         */
        queryWrapper.eq("lock_flag", LockFlagEnum.LOCK_FLAG_NO.getCode());
        queryWrapper.orderByDesc("id");
        //售后类型
        if (request.getAfterSaleType() != null) {
            queryWrapper.eq("after_sale_type", request.getAfterSaleType());
        }
        //商品名称
        if (request.getGoodsName() != null && !"".equals(request.getGoodsName())) {
            queryWrapper.like("goods_name", request.getGoodsName());
        }
        //供货商类型：1-供货商【非自营】 2-仓库【自营】
        if (request.getSupplierType() != null) {
            if (request.getSupplierId() != null) {
                queryWrapper.eq("supplier_id", request.getSupplierId());
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_ONE.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_NO.getCode());
                }
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_TWO.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_YES.getCode());
                }
            }
        }
        //手机号类型：1-购买人手机号 2-收件人手机号
        if (request.getPhoneType() != null) {
            if (request.getPhone() != null && !"".equals(request.getPhone())) {
                if (request.getPhoneType() == PhoneTypeEnum.PHONE_TYPE_BUY.getCode().byteValue()) {
                    queryWrapper.eq("buyer_phone", request.getPhone());
                }
                if (request.getPhoneType() == PhoneTypeEnum.PHONE_TYPE_RECEIVE.getCode().byteValue()) {
                    queryWrapper.eq("receiver_phone", request.getPhone());
                }
            }
        }
        //订单编号
        if (request.getOriginalOrderNo() != null && !"".equals(request.getOriginalOrderNo())) {
            queryWrapper.eq("original_order_no", request.getOriginalOrderNo());
        }
        //复选框选择ID
        if (request.getIdStr() != null && !"".equals(request.getIdStr())) {
            queryWrapper.in("id", request.getIdStr().split(","));
        }
        List<Compensation> compensations = compensationMapper.selectList(queryWrapper);
        List<ExportCompensationResponse> result = new ArrayList<>();
        compensations.forEach(compensation -> {
            ExportCompensationResponse exportCompensationResponse = new ExportCompensationResponse();
            BeanUtils.copyProperties(compensation, exportCompensationResponse);
            //根据订单ID和商品ID查询商品名称--【订单商品表】
            OrderGoodsServiceDetailsRequest orderGoodsServiceDetailsRequest = new OrderGoodsServiceDetailsRequest();
            orderGoodsServiceDetailsRequest.setOrderId(compensation.getOriginalOrderId());
            orderGoodsServiceDetailsRequest.setGoodsId(compensation.getCompensationGoodsId());
            OrderGoodsServiceDetailsResponse orderGoodsServiceDetailsResponse = iOrderService.findOrderGoodsDetails(orderGoodsServiceDetailsRequest);
            if (orderGoodsServiceDetailsResponse != null) {
                exportCompensationResponse.setGoodsName(orderGoodsServiceDetailsResponse.getGoodsName());
            }
            if (compensation.getRefundId() > 0) {
                QueryWrapper<RefundGoods> queryWrapperRefundGoods = new QueryWrapper<>();
                queryWrapperRefundGoods.eq("id", compensation.getRefundId());
                queryWrapperRefundGoods.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
                RefundGoods refundGoods = refundGoodsMapper.selectOne(queryWrapperRefundGoods);
                if (refundGoods != null) {
                    /*
                     * 售后类型 0-弃货退款 1-补偿款 2-补偿邮费
                     * 0-弃货退款：处理人
                     * 2-补偿邮费：收货人
                     */
                    if (compensation.getAfterSaleType().equals(AfterSaleEnum.AFTER_SALE_QHTK.getCode().byteValue())) {
                        exportCompensationResponse.setAfterTypeName("已弃货");
                        exportCompensationResponse.setOperatorName(refundGoods.getDealWithOperatorName());
                    } else {
                        exportCompensationResponse.setAfterTypeName("已收货");
                        exportCompensationResponse.setOperatorName(refundGoods.getReceivedOperatorName());
                    }
                }
            } else {
                exportCompensationResponse.setAfterTypeName("");
                exportCompensationResponse.setOperatorName("");
            }
            //售后类型对照
            AfterSaleEnum afterSaleEnum = EnumUtil.getByCode(compensation.getAfterSaleType().intValue(), AfterSaleEnum.class);
            if (afterSaleEnum != null) {
                exportCompensationResponse.setAfterSaleTypeStr(afterSaleEnum.getDesc());
            }
            //审核状态对照
            CheckStatusEnum checkStatusEnum = EnumUtil.getByCode(compensation.getCheckStatus().intValue(), CheckStatusEnum.class);
            if (checkStatusEnum != null) {
                exportCompensationResponse.setCheckStatusStr(checkStatusEnum.getDesc());
            }
            result.add(exportCompensationResponse);
        });
        ExportExcelCommonResponse<ExportCompensationResponse> response = new ExportExcelCommonResponse<>();
        response.setData(result);
        response.setFileName(System.currentTimeMillis() + ".xlsx");
        return response;
    }

    /**
     * 待审核导出excel
     *
     * @param request
     * @return
     */
    public ExportExcelCommonResponse<ExportCompensationResponse> exportExcelCheck(ExportCompensationRequest request) {
        request.checkRequest();
        QueryWrapper<Compensation> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("check_status", CheckStatusEnum.CHECK_STATUS_WAIT.getCode());
        /*
         * 补偿邮费
         * 默认锁定，锁定的不展示
         * 是否锁定: 0-否 1-是
         */
        queryWrapper.eq("lock_flag", LockFlagEnum.LOCK_FLAG_NO.getCode());
        queryWrapper.orderByDesc("id");
        //售后类型
        if (request.getAfterSaleType() != null) {
            queryWrapper.eq("after_sale_type", request.getAfterSaleType());
        }
        //商品名称
        if (request.getGoodsName() != null && !"".equals(request.getGoodsName())) {
            queryWrapper.like("goods_name", request.getGoodsName());
        }
        //供货商类型：1-供货商【非自营】 2-仓库【自营】
        if (request.getSupplierType() != null) {
            if (request.getSupplierId() != null) {
                queryWrapper.eq("supplier_id", request.getSupplierId());
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_ONE.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_NO.getCode());
                }
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_TWO.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_YES.getCode());
                }
            }
        }
        //手机号类型：1-购买人手机号 2-收件人手机号
        if (request.getPhoneType() != null) {
            if (request.getPhone() != null && !"".equals(request.getPhone())) {
                if (request.getPhoneType() == PhoneTypeEnum.PHONE_TYPE_BUY.getCode().byteValue()) {
                    queryWrapper.eq("buyer_phone", request.getPhone());
                }
                if (request.getPhoneType() == PhoneTypeEnum.PHONE_TYPE_RECEIVE.getCode().byteValue()) {
                    queryWrapper.eq("receiver_phone", request.getPhone());
                }
            }
        }        //订单编号
        if (request.getOriginalOrderNo() != null && !"".equals(request.getOriginalOrderNo())) {
            queryWrapper.eq("original_order_no", request.getOriginalOrderNo());
        }
        //复选框选择ID
        if (request.getIdStr() != null && !"".equals(request.getIdStr())) {
            queryWrapper.in("id", request.getIdStr().split(","));
        }
        List<Compensation> compensations = compensationMapper.selectList(queryWrapper);
        List<ExportCompensationResponse> result = new ArrayList<>();
        compensations.forEach(compensation -> {
            ExportCompensationResponse exportCompensationResponse = new ExportCompensationResponse();
            BeanUtils.copyProperties(compensation, exportCompensationResponse);
            //根据订单ID和商品ID查询商品名称--【订单商品表】
            OrderGoodsServiceDetailsRequest orderGoodsServiceDetailsRequest = new OrderGoodsServiceDetailsRequest();
            orderGoodsServiceDetailsRequest.setOrderId(compensation.getOriginalOrderId());
            orderGoodsServiceDetailsRequest.setGoodsId(compensation.getCompensationGoodsId());
            OrderGoodsServiceDetailsResponse orderGoodsServiceDetailsResponse = iOrderService.findOrderGoodsDetails(orderGoodsServiceDetailsRequest);
            if (orderGoodsServiceDetailsResponse != null) {
                exportCompensationResponse.setGoodsName(orderGoodsServiceDetailsResponse.getGoodsName());
            }
            if (compensation.getRefundId() > 0) {
                QueryWrapper<RefundGoods> queryWrapperRefundGoods = new QueryWrapper<>();
                queryWrapperRefundGoods.eq("id", compensation.getRefundId());
                queryWrapperRefundGoods.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
                RefundGoods refundGoods = refundGoodsMapper.selectOne(queryWrapperRefundGoods);
                if (refundGoods != null) {
                    /*
                     * 售后类型 0-弃货退款 1-补偿款 2-补偿邮费
                     * 0-弃货退款：处理人
                     * 2-补偿邮费：收货人
                     */
                    if (compensation.getAfterSaleType().equals(AfterSaleEnum.AFTER_SALE_QHTK.getCode().byteValue())) {
                        exportCompensationResponse.setAfterTypeName("已弃货");
                        exportCompensationResponse.setOperatorName(refundGoods.getDealWithOperatorName());
                    } else {
                        exportCompensationResponse.setAfterTypeName("已收货");
                        exportCompensationResponse.setOperatorName(refundGoods.getReceivedOperatorName());
                    }
                }
            } else {
                exportCompensationResponse.setAfterTypeName("");
                exportCompensationResponse.setOperatorName("");
            }
            //售后类型对照
            AfterSaleEnum afterSaleEnum = EnumUtil.getByCode(compensation.getAfterSaleType().intValue(), AfterSaleEnum.class);
            if (afterSaleEnum != null) {
                exportCompensationResponse.setAfterSaleTypeStr(afterSaleEnum.getDesc());
            }
            //审核状态对照
            CheckStatusEnum checkStatusEnum = EnumUtil.getByCode(compensation.getCheckStatus().intValue(), CheckStatusEnum.class);
            if (checkStatusEnum != null) {
                exportCompensationResponse.setCheckStatusStr(checkStatusEnum.getDesc());
            }
            result.add(exportCompensationResponse);
        });
        ExportExcelCommonResponse<ExportCompensationResponse> response = new ExportExcelCommonResponse<>();
        response.setData(result);
        response.setFileName(System.currentTimeMillis() + ".xlsx");
        return response;
    }

    /**
     * 已同意导出excel
     *
     * @param request
     * @return
     */
    public ExportExcelCommonResponse<ExportCompensationResponse> exportExcelAgree(ExportCompensationStepRequest
                                                                                          request) {
        request.checkRequest();
        QueryWrapper<Compensation> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("check_status", CheckStatusEnum.CHECK_STATUS_AGREE.getCode());
        /*
         * 补偿邮费
         * 默认锁定，锁定的不展示
         * 是否锁定: 0-否 1-是
         */
        queryWrapper.eq("lock_flag", LockFlagEnum.LOCK_FLAG_NO.getCode());
        queryWrapper.orderByDesc("id");
        //售后类型
        if (request.getAfterSaleType() != null) {
            queryWrapper.eq("after_sale_type", request.getAfterSaleType());
        }
        //商品名称
        if (request.getGoodsName() != null && !"".equals(request.getGoodsName())) {
            queryWrapper.like("goods_name", request.getGoodsName());
        }
        //供货商类型：1-供货商【非自营】 2-仓库【自营】
        if (request.getSupplierType() != null) {
            if (request.getSupplierId() != null) {
                queryWrapper.eq("supplier_id", request.getSupplierId());
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_ONE.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_NO.getCode());
                }
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_TWO.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_YES.getCode());
                }
            }
        }
        //复选框选择ID
        if (request.getIdStr() != null && !"".equals(request.getIdStr())) {
            queryWrapper.in("id", request.getIdStr().split(","));
        }
        List<Compensation> compensations = compensationMapper.selectList(queryWrapper);
        List<ExportCompensationResponse> result = new ArrayList<>();
        compensations.forEach(compensation -> {
            ExportCompensationResponse exportCompensationResponse = new ExportCompensationResponse();
            BeanUtils.copyProperties(compensation, exportCompensationResponse);
            //根据订单ID和商品ID查询商品名称--【订单商品表】
            OrderGoodsServiceDetailsRequest orderGoodsServiceDetailsRequest = new OrderGoodsServiceDetailsRequest();
            orderGoodsServiceDetailsRequest.setOrderId(compensation.getOriginalOrderId());
            orderGoodsServiceDetailsRequest.setGoodsId(compensation.getCompensationGoodsId());
            OrderGoodsServiceDetailsResponse orderGoodsServiceDetailsResponse = iOrderService.findOrderGoodsDetails(orderGoodsServiceDetailsRequest);
            if (orderGoodsServiceDetailsResponse != null) {
                exportCompensationResponse.setGoodsName(orderGoodsServiceDetailsResponse.getGoodsName());
            }
            if (compensation.getRefundId() > 0) {
                QueryWrapper<RefundGoods> queryWrapperRefundGoods = new QueryWrapper<>();
                queryWrapperRefundGoods.eq("id", compensation.getRefundId());
                queryWrapperRefundGoods.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
                RefundGoods refundGoods = refundGoodsMapper.selectOne(queryWrapperRefundGoods);
                if (refundGoods != null) {
                    /*
                     * 售后类型 0-弃货退款 1-补偿款 2-补偿邮费
                     * 0-弃货退款：处理人
                     * 2-补偿邮费：收货人
                     */
                    if (compensation.getAfterSaleType().equals(AfterSaleEnum.AFTER_SALE_QHTK.getCode().byteValue())) {
                        exportCompensationResponse.setAfterTypeName("已弃货");
                        exportCompensationResponse.setOperatorName(refundGoods.getDealWithOperatorName());
                    } else {
                        exportCompensationResponse.setAfterTypeName("已收货");
                        exportCompensationResponse.setOperatorName(refundGoods.getReceivedOperatorName());
                    }
                }
            } else {
                exportCompensationResponse.setAfterTypeName("");
                exportCompensationResponse.setOperatorName("");
            }
            //售后类型对照
            AfterSaleEnum afterSaleEnum = EnumUtil.getByCode(compensation.getAfterSaleType().intValue(), AfterSaleEnum.class);
            if (afterSaleEnum != null) {
                exportCompensationResponse.setAfterSaleTypeStr(afterSaleEnum.getDesc());
            }
            //审核状态对照
            CheckStatusEnum checkStatusEnum = EnumUtil.getByCode(compensation.getCheckStatus().intValue(), CheckStatusEnum.class);
            if (checkStatusEnum != null) {
                exportCompensationResponse.setCheckStatusStr(checkStatusEnum.getDesc());
            }
            result.add(exportCompensationResponse);
        });
        ExportExcelCommonResponse<ExportCompensationResponse> response = new ExportExcelCommonResponse<>();
        response.setData(result);
        response.setFileName(System.currentTimeMillis() + ".xlsx");
        return response;
    }


    /**
     * 已拒绝导出excel
     *
     * @param request
     * @return
     */
    public ExportExcelCommonResponse<ExportCompensationResponse> exportExcelRefuse(ExportCompensationStepRequest
                                                                                           request) {
        request.checkRequest();
        QueryWrapper<Compensation> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("check_status", CheckStatusEnum.CHECK_STATUS_REFUSE.getCode());
        /*
         * 补偿邮费
         * 默认锁定，锁定的不展示
         * 是否锁定: 0-否 1-是
         */
        queryWrapper.eq("lock_flag", LockFlagEnum.LOCK_FLAG_NO.getCode());
        queryWrapper.orderByDesc("id");
        //售后类型
        if (request.getAfterSaleType() != null) {
            queryWrapper.eq("after_sale_type", request.getAfterSaleType());
        }
        //商品名称
        if (request.getGoodsName() != null && !"".equals(request.getGoodsName())) {
            queryWrapper.like("goods_name", request.getGoodsName());
        }
        //供货商类型：1-供货商【非自营】 2-仓库【自营】
        if (request.getSupplierType() != null) {
            if (request.getSupplierId() != null) {
                queryWrapper.eq("supplier_id", request.getSupplierId());
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_ONE.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_NO.getCode());
                }
                if (request.getSupplierType() == com.jumi.microservice.constant.reissue.SupplierTypeEnum.SUPPLIER_TYPE_TWO.getCode().byteValue()) {
                    queryWrapper.eq("self_flag", SelfFlagEnum.SELF_FLAG_YES.getCode());
                }
            }
        }
        //复选框选择ID
        if (request.getIdStr() != null && !"".equals(request.getIdStr())) {
            queryWrapper.in("id", request.getIdStr().split(","));
        }
        List<Compensation> compensations = compensationMapper.selectList(queryWrapper);
        List<ExportCompensationResponse> result = new ArrayList<>();
        compensations.forEach(compensation -> {
            ExportCompensationResponse exportCompensationResponse = new ExportCompensationResponse();
            BeanUtils.copyProperties(compensation, exportCompensationResponse);
            //根据订单ID和商品ID查询商品名称--【订单商品表】
            OrderGoodsServiceDetailsRequest orderGoodsServiceDetailsRequest = new OrderGoodsServiceDetailsRequest();
            orderGoodsServiceDetailsRequest.setOrderId(compensation.getOriginalOrderId());
            orderGoodsServiceDetailsRequest.setGoodsId(compensation.getCompensationGoodsId());
            OrderGoodsServiceDetailsResponse orderGoodsServiceDetailsResponse = iOrderService.findOrderGoodsDetails(orderGoodsServiceDetailsRequest);
            if (orderGoodsServiceDetailsResponse != null) {
                exportCompensationResponse.setGoodsName(orderGoodsServiceDetailsResponse.getGoodsName());
            }
            if (compensation.getRefundId() > 0) {
                QueryWrapper<RefundGoods> queryWrapperRefundGoods = new QueryWrapper<>();
                queryWrapperRefundGoods.eq("id", compensation.getRefundId());
                queryWrapperRefundGoods.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
                RefundGoods refundGoods = refundGoodsMapper.selectOne(queryWrapperRefundGoods);
                if (refundGoods != null) {
                    /*
                     * 售后类型 0-弃货退款 1-补偿款 2-补偿邮费
                     * 0-弃货退款：处理人
                     * 2-补偿邮费：收货人
                     */
                    if (compensation.getAfterSaleType().equals(AfterSaleEnum.AFTER_SALE_QHTK.getCode().byteValue())) {
                        exportCompensationResponse.setAfterTypeName("已弃货");
                        exportCompensationResponse.setOperatorName(refundGoods.getDealWithOperatorName());
                    } else {
                        exportCompensationResponse.setAfterTypeName("已收货");
                        exportCompensationResponse.setOperatorName(refundGoods.getReceivedOperatorName());
                    }
                }
            } else {
                exportCompensationResponse.setAfterTypeName("");
                exportCompensationResponse.setOperatorName("");
            }
            //售后类型对照
            AfterSaleEnum afterSaleEnum = EnumUtil.getByCode(compensation.getAfterSaleType().intValue(), AfterSaleEnum.class);
            if (afterSaleEnum != null) {
                exportCompensationResponse.setAfterSaleTypeStr(afterSaleEnum.getDesc());
            }
            //审核状态对照
            CheckStatusEnum checkStatusEnum = EnumUtil.getByCode(compensation.getCheckStatus().intValue(), CheckStatusEnum.class);
            if (checkStatusEnum != null) {
                exportCompensationResponse.setCheckStatusStr(checkStatusEnum.getDesc());
            }
            result.add(exportCompensationResponse);
        });
        ExportExcelCommonResponse<ExportCompensationResponse> response = new ExportExcelCommonResponse<>();
        response.setData(result);
        response.setFileName(System.currentTimeMillis() + ".xlsx");
        return response;
    }

    /**
     * 售后类型--对照字典
     */
    public Map<Integer, String> getAfterSale() {
        Map<Integer, String> m = new HashMap<>();
        m.put(AfterSaleEnum.AFTER_SALE_QHTK.getCode(), AfterSaleEnum.AFTER_SALE_QHTK.getDesc());
        m.put(AfterSaleEnum.AFTER_SALE_BCK.getCode(), AfterSaleEnum.AFTER_SALE_BCK.getDesc());
        m.put(AfterSaleEnum.AFTER_SALE_BCYF.getCode(), AfterSaleEnum.AFTER_SALE_BCYF.getDesc());
        return m;
    }

    /**
     * 审核状态--对照字典
     */
    public Map<Integer, String> getCheckStatus() {
        Map<Integer, String> m = new HashMap<>();
        m.put(CheckStatusEnum.CHECK_STATUS_WAIT.getCode(), CheckStatusEnum.CHECK_STATUS_WAIT.getDesc());
        m.put(CheckStatusEnum.CHECK_STATUS_REFUSE.getCode(), CheckStatusEnum.CHECK_STATUS_REFUSE.getDesc());
        m.put(CheckStatusEnum.CHECK_STATUS_AGREE.getCode(), CheckStatusEnum.CHECK_STATUS_AGREE.getDesc());
        return m;
    }

    /**
     * 生成订单号
     */
    private String generateOrderSn() {
        String time = DateUtil.getAllMSTime().substring(2);
        int randomInt = ThreadLocalRandom.current().nextInt(10, 100);
        return "BC" + time + randomInt;
    }
}
